{% extends 'PHPDishWebBundle:Book:view_common.html.twig' %}

{% set tab = 'summary' %}

{% set isGranted = is_granted('edit', book) %}
{% block book_content %}
    {#<div class="book-box">#}
        <ul class="list-group book-summary" data-role="summary">
            {% for chapter in chaptersTree %}
            <li class="chapter list-group-item" data-role="chapter" data-id="{{ chapter.id }}" data-title="{{ chapter.title }}">
                <div class="clearfix">
                    <span class="name">
                        {% if chapter.children|length > 0 %}
                            <i class="fa fa-caret-down"></i>
                            {{ loop.index }}. {{ chapter.title }}
                        {% else %}
                            <i class="fa fa-file-text"></i>
                            {{ loop.index }}. <a href="{{ path('book_read', {slug: book.slug, chapterId: chapter.id}) }}">{{ chapter.title }}</a>
                        {% endif %}
                    </span>
                    {% if isGranted %}
                    <span class="action" data-role="action">
                        {% if chapter.children|length > 0 %}
                            <a title="{{ 'book.edit_this_chapter'|trans }}" data-toggle="tooltip" data-role="edit" href="javascript:void(0);"><i class="fa fa-pencil-square-o"></i></a>
                        {% else %}
                            <a title="{{ 'book.edit_this_chapter'|trans }}" data-toggle="tooltip" href="{{ path('book_edit_chapter', {slug: book.slug, id: chapter.id}) }}"><i class="fa fa-pencil-square-o"></i></a>
                        {% endif %}
                        <a title="{{ 'book.add_sub_chapter'|trans }}" data-toggle="tooltip" data-role="add-sub" href="{{ path('book_add_chapter', {slug: book.slug, summary: chapter.id}) }}"><i class="fa fa-plus-square-o"></i></a>
                        {% if chapter.children|length == 0 %}
                        <a title="{{ 'book.delete_this_chapter'|trans }}" data-toggle="tooltip"  data-role="delete" href="javascript:void(0);"><i class="fa fa-trash-o"></i></a>
                        {% endif %}
                        <a title="{{ 'book.move_up'|trans }}" data-toggle="tooltip" data-role="move" data-direction="up" href="javascript:void(0);">
                            <i class="fa fa-arrow-circle-up"></i>
                        </a>
                        <a title="{{ 'book.move_down'|trans }}" data-toggle="tooltip" data-role="move" data-direction="down" href="javascript:void(0);">
                            <i class="fa fa-arrow-circle-down"></i>
                        </a>
                    </span>
                    {% endif %}
                </div>
                {% if chapter.children|length > 0 %}
                <ul class="sub-chapter list-unstyled">
                    {% set summaryIndex = loop.index %}
                    {% for children in chapter.children %}
                        <li data-role="sub-chapter" data-id="{{ children.id  }}">
                            <a href="{{ path('book_read', {'slug': book.slug, 'chapterId': children.id}) }}">
                                <i class="fa fa-file-text"></i>  {{ summaryIndex }}.{{ loop.index }} {{ children.title }}
                            </a>
                            {% if isGranted %}
                            <span class="action" data-role="action">
                                <a title="{{ 'book.edit_this_chapter'|trans }}" data-toggle="tooltip" href="{{ path('book_edit_chapter', {slug: book.slug, id: children.id}) }}"><i class="fa fa-pencil-square-o"></i></a>
                                <a title="{{ 'book.delete_this_chapter'|trans }}" data-toggle="tooltip"  data-role="delete" href="javascript:void(0);"><i class="fa fa-trash-o"></i></a>
                                <a title="{{ 'book.move_up'|trans }}" data-toggle="tooltip" data-role="move" data-direction="up" href="javascript:void(0);">
                                    <i class="fa fa-arrow-circle-up"></i>
                                </a>
                                <a title="{{ 'book.move_down'|trans }}" data-toggle="tooltip" data-role="move" data-direction="down" href="javascript:void(0);">
                                    <i class="fa fa-arrow-circle-down"></i>
                                </a>
                            </span>
                            {% endif %}
                        </li>
                    {% endfor %}
                </ul>
                {% endif %}
            </li>
            {% endfor %}
            {% if isGranted %}
                <li class="list-group-item">
                    <button class="btn u-btn-primary" data-role="add-chapter"><i class="fa fa-plus-square-o"></i> {{ 'book.add_chapter'|trans }}</button>
                </li>
            {% endif %}
        </ul>
    {#</div>#}
{% endblock %}